<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="100px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="12">
          <el-form-item label="打印模板:" prop="modelFileName">
            <hey-select v-model="formModel.modelFileName" :disabled="disabledModel" filterable clearable clcd="print_model_cd"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="打印机名:" prop="printerName">
            <el-input v-model="formModel.printerName"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="打印份数:" prop="printNum">
            <el-input-number v-model="formModel.printNum" align="left" controls-position="right" :max="999" :min="1" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="服务状态:" prop="status">
            <hey-select v-model="formModel.status" :clearable="false" clcd="is_effective_cd" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'PrintConfigMnt',
  props: ['pageType', 'editData'],
  data() {
    return {
      disabledModel:false,
      formModel: {
        rcrdId: '',
        modelFileName: '',
        printerName: '',
        printNum: '',
        status: '1',
      },
      rules: {
      }
    }
  },
  computed: {},
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$form = this.$refs.form
      const { pageType, editData, formModel } = this
      if (pageType === 'edit') {
        this.assignData(editData, formModel)
        this.disabledModel = true
      }
      this.initRules()
    },
    initRules() {
      const REQUIRED_MSG = this.CONST.REQUIRED_MSG
      this.rules = {
        modelFileName: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        printerName: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        printNum: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        status: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
      }
      this.$nextTick(_ => {
        this.$form.clearValidate()
      })
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          const { pageType, formModel } = this
          const param = { ...formModel }
          const operateType = pageType === 'edit' ? '02' : '01'
          param.operateType = operateType
          const url = '/printModelConfig/maintainPrintModelConfig'
          const tip = pageType === 'edit' ? '修改成功！' : '新增成功！'
          this.post(url, param).then(res => {
            this.$info(tip, () => {
              this.$emit('mntSuc', res)
              this.closeDialog()
            })
          })
        }
      })
    },
    closeDialog() {
      this.$parent.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
